import time


def read_log(log_name):
    log_file = open(log_name, 'r',encoding='utf8')
    data = log_file.readlines()
    log_file.close()
    return data


def log_tool(log_file):
    try:
        while True:
            lines = read_log(log_file)
            count_v = 0
            count_d = 0
            count_i = 0
            count_w = 0
            count_e = 0
            count_f = 0
            count_s = 0
            for line in lines:
                if line[31:32] == 'V':
                    count_v += 1
                elif line[31:32] == 'D':
                    count_d += 1
                elif line[31:32] == 'I':
                    count_i += 1
                elif line[31:32] == 'W':
                    count_w += 1
                elif line[31:32] == 'E':
                    count_e += 1
                    print(line)
                elif line[31:32] == 'F':
                    count_f += 1
                elif line[31:32] == 'S':
                    count_s += 1
            print('-----------------')
            print(f'Verbose:{count_v}')
            print(f'Debug:{count_d}')
            print(f'Info:{count_i}')
            print(f'Warn:{count_w}')
            print(f'Error:{count_e}')
            print(f'Fatal:{count_f}')
            print(f'Silent:{count_s}')
            print('-----------------')
            time.sleep(2)
    except KeyboardInterrupt:
        print('日志分析工具已关闭')

if __name__ == '__main__':
    log_tool('a.txt')
